home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 04 / dlring.ads < prev    next >
Text File  |  1991-05-09  |  3KB  |  67 lines

  1. -- ========================= begin comment ===========================
  2. -- dlring.ads
  3. --
  4. --             *******   PACKAGE SPECIFICATION  ******
  5. --                   for a simple doubly-linked ring
  6. --                   data structure - partial implementation
  7. --
  8. --     There are many ways to implement a doubly-linked ring.
  9. --     This listing is the Ada solution submitted by one of my
  10. --     undergraduate computer science students. It can be improved
  11. --     and made more reliable.  Notably, the use of a counter to
  12. --     control subprograms that traverse the ring contains some
  13. --     potential dangers.  It might be better to have a "marked"
  14. --     node that serves as the starting and ending point for any
  15. --     traversal algorithm.  This is a good data structure on which
  16. --     to experiment. Try to make it more efficient. Try to make it
  17. --     more reliable.  Add some additional functionality to it.
  18. -- ========================= end of comment =========================
  19.  
  20. with TEXT_IO;
  21. generic    -- define generic formal parameters
  22.  
  23.       type DLRing_Type is private;
  24.       with function  EQUAL (LEFT, RIGHT : DLRing_Type) return BOOLEAN;
  25.  
  26. package DLRing is
  27.            --
  28.    type DIRECTION_TYPE     is (FORWARD, BACKWARD); -- rotation
  29.    type FINGER_TYPE        is limited private;
  30.  
  31.    procedure ROTATE   (DIRECTION    : in     DIRECTION_TYPE;
  32.                        FINGER       : in out FINGER_TYPE);
  33.  
  34.    procedure INSERT   (ITEM         : in     DLRing_Type;
  35.                        FINGER       : in out FINGER_TYPE);
  36.  
  37.    procedure REPLACE  (ITEM         : in     DLRing_Type;
  38.                        FINGER       : in out FINGER_TYPE);
  39.  
  40.    procedure DELETE   (FINGER       : in out FINGER_TYPE;
  41.                        EMPTY_ERROR  :    out BOOLEAN);
  42.  
  43.    procedure PEEK     (ITEM         :    out DLRing_Type;
  44.                        FINGER       : in out FINGER_TYPE;
  45.                        EMPTY_ERROR  :    out BOOLEAN);
  46.  
  47.    procedure SEARCH   (FINGER       : in out FINGER_TYPE;
  48.                        ITEM         : in     DLRing_Type;
  49.                        FOUND        :    out BOOLEAN);
  50.  
  51.    function  Is_Count (Finger : Finger_Type) return Natural;
  52.  
  53. private
  54.           type CELL;                    -- an incomplete type
  55.           type POINTER is access CELL;  -- set up a pointer type
  56.           type FINGER_TYPE is           -- keeps track of where
  57.                record                   -- we are in the ring
  58.                       PTR  : POINTER;
  59.                       CNTR : NATURAL := 0;
  60.                end record;
  61. end DLRing;
  62. -- ++++++++++++++++ End of Package Specification ++++++++++++++++++++
  63.  
  64.  
  65.  
  66.  
  67.